﻿using System;
using System.Data;
using System.Data.Common;
using YiYiTong.Rocket.Entity;
using YiYiTong.Rocket.Helper;

namespace YiYiTong.Rocket.DataAccess
{
    public class JingjiaDataAccess
    {
        #region 单例模式
        private JingjiaDataAccess()
        {
        }

        private static JingjiaDataAccess _instance;
        private static readonly object _syncObject = new object();

        public static JingjiaDataAccess Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_syncObject)
                    {
                        if (_instance == null)
                        {
                            _instance = new JingjiaDataAccess();
                        }
                    }
                }
                return _instance;
            }
        }
        #endregion 单例模式

        /// <summary>
        /// 竞价列表查询
        /// </summary>
        /// <param>1 直播 2 预热 3 爆款 4竞价</param>
        /// <param name="brand_id">品牌id</param>
        /// <param name="category_id">分类id</param>
        /// <param name="selKey">搜索关键字</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageRows"></param>
        /// <returns></returns>
        public DataSet GetJingjiaList(long jingjia_config_id , long uid,long brand_id, long category_id, string selKey, int pageIndex, int pageRows)
        {
            DataSet ds = null;
            try
            {
                DBHelper db = DBFactory.ApiDB;
                string storeName = "proc_jingjia_getlist";
                DbCommand Procdbcomm = db.GetStoredProcCommand(storeName);
                db.AddInParameter(Procdbcomm, "@jingjia_config_id", DbType.Int64, jingjia_config_id);
                db.AddInParameter(Procdbcomm, "@uid", DbType.Int64, uid);
                db.AddInParameter(Procdbcomm, "@brand_id", DbType.Int64, brand_id);
                db.AddInParameter(Procdbcomm, "@category_id", DbType.Int64, category_id);
                db.AddInParameter(Procdbcomm, "@MPN", DbType.String, selKey);
                db.AddInParameter(Procdbcomm, "@pageIndex", DbType.Int32, pageIndex);
                db.AddInParameter(Procdbcomm, "@pageRows", DbType.Int32, pageRows);
                ds = db.ExecuteDataSet(Procdbcomm);
            }
            catch (Exception ex)
            {
                //记录日志
                LogHelper.Error("竞价查询-GetJingjiaList" + ex.ToString());
            }
            return ds;
        }
    }
}
